<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="js/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootoast.css">

    <script src="js/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="js/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script src="js/bootoast.js"></script>
    <style>
        .login-box{
            padding: 20px;
            border-radius: 15px;
            background-color: aqua;
            margin-top: 250px;
        }
        body{
            background-image: url(img/xian.png);
            background-size: cover;
        }
    </style>

    <script>
        $(function(){
            $('#btnLogin').click(function(){
                var account = $('#account').val();
                var pass = $('pass').val();
                if(account == ''){
                    bootoast({
                        message:'账号/手机不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }

                if(pass == ''){
                    bootoast({
                        message:'密码不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }

                $.ajax({
                    url:'login',
                    type:'post',
                    cache:false,
                    data: {
                        account: $('#account').val(),
                        pass: $('#pass').val()
                    },
                    dataType:'json',
                    success:function (rst) {
                        if(rst.code == -1){
                            bootoast({
                                message:rst.msg,
                                type:'danger',
                                position:'top',
                                timeout:2
                            });
                        }else {
                            bootoast({
                                message:rst.msg,
                                type:'success',
                                position:'top',
                                timeout:2
                            });
                            //登录成功用户信息保存
                            sessionStorage.setItem("adminId",rst.data.adminId);
                            sessionStorage.setItem("nickName",rst.data.nickName);

                            //跳转页面
                            setTimeout(function () {
                                location.href='home.html';
                            },2000);
                        }
                    },error:function (err) {
                        console.info(err);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-4 col-sm-offset-4">
                <div class="login-box">
                    <h2 class="text-center">来了啊商城登录</h2>
                    <form action="" class="form-horizontal">
                        <div class="form-group">
                            <label for="account" class="col-xs-3 control-label">账号/手机</label>
                            <div class="col-xs-9">
                                <input type="text" name="" id="account" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pass" class="col-xs-3 control-label">密码</label>
                            <div class="col-xs-9">
                                <input type="password" name="" id="pass" class="form-control">
                            </div>
                        </div>
                        <div class="form-group text-center">
                            <input type="button" id="btnLogin" class="btn btn-primary" value="登录">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>